<?php defined('BASEPATH') OR die('No direct access allowed.');
/**
 * Description of "signup"
 *
 * Created on Dec 21, 2010
 * @author Ramon Gutierrez
 * @copyright Bitstop Network Services Inc.
 * @version 0.1
 */
?>
            <script type="text/javascript">
			// <![CDATA[
			  $(document).ready(function() {
			    var jVal = {
				  'company_name' : function() {
					$("#company_name_info").remove();
	                $('body').append('<'+'div id="company_name_info" class="info"><'+'/div>');
	                var nameInfo = $('#company_name_info');
	                var ele = $('#company_name');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 1) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; provide a name').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'industry_type' : function() {
					$("#industry_type_info").remove();
	                $('body').append('<'+'div id="industry_type_info" class="info"><'+'/div>');
	                var nameInfo = $('#industry_type_info');
	                var ele = $('#industry_type');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(!ele.val()) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; select an industry type').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'first_name' : function() {
					$("#first_name_info").remove();
	                $('body').append('<'+'div id="first_name_info" class="info"><'+'/div>');
	                var nameInfo1 = $('#first_name_info');
	                var ele = $('#first_name');
	                var pos = ele.offset();
					
	                nameInfo1.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 1) {
	                  jVal.errors = true;
	                  nameInfo1.removeClass('correct').addClass('error').html('&larr; enter first name').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo1.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'last_name' : function() {
					$("#last_name_info").remove();
	                $('body').append('<'+'div id="last_name_info" class="info"><'+'/div>');
	                var nameInfo2 = $('#last_name_info');
	                var ele = $('#last_name');
	                var pos = ele.offset();
					
	                nameInfo2.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 1) {
	                  jVal.errors = true;
	                  nameInfo2.removeClass('correct').addClass('error').html('&larr; enter last name').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo2.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'street_address' : function() {
					$("#street_address_info").remove();
	                $('body').append('<'+'div id="street_address_info" class="info"><'+'/div>');
	                var nameInfo = $('#street_address_info');
	                var ele = $('#street_address');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 1) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; provide street address').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'city' : function() {
					$("#city_info").remove();
	                $('body').append('<'+'div id="city_info" class="info"><'+'/div>');
	                var nameInfo = $('#city_info');
	                var ele = $('#city');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 1) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; provide city name').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'state' : function() {
					$("#state_info").remove();
	                $('body').append('<'+'div id="state_info" class="info"><'+'/div>');
	                var nameInfo = $('#state_info');
	                var ele = $('#state');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 1) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; provide state or province').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'country_id' : function() {
					$("#country_id_info").remove();
	                $('body').append('<'+'div id="country_id_info" class="info"><'+'/div>');
	                var nameInfo = $('#country_id_info');
	                var ele = $('#country_id');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 1) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; select a country').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'zip' : function() {
					$("#zip_info").remove();
	                $('body').append('<'+'div id="zip_info" class="info"><'+'/div>');
	                var nameInfo = $('#zip_info');
	                var ele = $('#zip');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                ele.removeClass('wrong').addClass('normal');
	              },
				  
				  'contact_number' : function() {
					$("#contact_number_info").remove();
	                $('body').append('<'+'div id="contact_number_info" class="info"><'+'/div>');
	                var nameInfo = $('#contact_number_info');
	                var ele = $('#contact_number');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 1) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; need your contact number').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'email' : function() {
					$("#email_info").remove();
	                $('body').append('<'+'div id="email_info" class="info"><'+'/div>');
	                var nameInfo = $('#email_info');
	                var ele = $('#email');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
					var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
					
	                if(!pattern.test(ele.val())) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; need a valid e-mail address').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  $.post('<?php echo site_url('signup/check'); ?>', { type: 'email', val: ele.val() }, function(data) {
						if(data) {
					      nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                      ele.removeClass('wrong').addClass('normal');
						} else {
						  nameInfo.removeClass('correct').addClass('error').html('&larr; this e-mail address is already in use').show();
	                      ele.removeClass('normal').addClass('wrong');
						}
					  });
	                }
	              },
				  
				  'username' : function() {
					$("#username_info").remove();
	                $('body').append('<'+'div id="username_info" class="info"><'+'/div>');
	                var nameInfo = $('#username_info');
	                var ele = $('#acct_username');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 5) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; at least 5 characters').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
					  $.post('<?php echo site_url('signup/check'); ?>', { type: 'username', val: ele.val() }, function(data) {
						if(data) {
					      nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                      ele.removeClass('wrong').addClass('normal');
						} else {
						  nameInfo.removeClass('correct').addClass('error').html('&larr; this username is already taken').show();
	                      ele.removeClass('normal').addClass('wrong');
						}
					  });
	                }
	              },
				  
				  'password' : function() {
					$("#password_info").remove();
	                $('body').append('<'+'div id="password_info" class="info"><'+'/div>');
	                var nameInfo = $('#password_info');
	                var ele = $('#acct_password');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val().length < 7) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; at least 7 characters').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
					
					if($("#acct_confirm").val().length > 0) {
					  $("#acct_confirm").change();
					}
	              },
				  
				  'confirmation' : function() {
					$("#confirm_info").remove();
	                $('body').append('<'+'div id="confirm_info" class="info"><'+'/div>');
	                var nameInfo = $('#confirm_info');
	                var ele = $('#acct_confirm');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if(ele.val() != $("#acct_password").val()) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; must match password choice').show();
	                  ele.removeClass('normal').addClass('wrong');
	                } else if($("#acct_password").val().length >=7) {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                  ele.removeClass('wrong').addClass('normal');
	                }
	              },
				  
				  'tos' : function() {
					$("#tos_info").remove();
	                $('body').append('<'+'div id="tos_info" class="info"><'+'/div>');
	                var nameInfo = $('#tos_info');
	                var ele = $('#tos-box');
	                var pos = ele.offset();
					
	                nameInfo.css({top: pos.top-3,
	                  left: pos.left+ele.width()+10
	                });
					
	                if($('input[name="tos"]:checked').length < 1) {
	                  jVal.errors = true;
	                  nameInfo.removeClass('correct').addClass('error').html('&larr; you gotta say yes to sign up').show();
	                } else {
	                  nameInfo.removeClass('error').addClass('correct').html('&radic;').show();
	                }
	              }
				};
				
				// bind jVal function
                $('#company_name').change(jVal.company_name).blur(jVal.company_name);
				$('#industry_type').change(jVal.industry_type).blur(jVal.industry_type);
				$('#first_name').change(jVal.first_name).blur(jVal.first_name);
				$('#last_name').change(jVal.last_name).blur(jVal.last_name);
				$('#street_address').change(jVal.street_address).blur(jVal.street_address);
				$('#city').change(jVal.city).blur(jVal.city);
				$('#state').change(jVal.state).blur(jVal.state);
				$('#country_id').change(jVal.country_id).blur(jVal.country_id);
				$('#zip').change(jVal.zip).blur(jVal.zip);
				$('#email').change(jVal.email).blur(jVal.email);
				$('#contact_number').change(jVal.contact_number).blur(jVal.contact_number);
				$('#acct_username').change(jVal.username).blur(jVal.username);
				$('#acct_password').change(jVal.password).blur(jVal.password);
				$('#acct_confirm').change(jVal.confirmation).blur(jVal.confirmation);
				$('#tos').change(jVal.tos).blur(jVal.tos);
			  });
			  
			  function revalidate() {
				$('#company_name').change();
				$('#industry_type').change();
				$('#first_name').change();
				$('#last_name').change();
				$('#street_address').change();
				$('#city').change();
				$('#state').change();
				$('#country_id').change();
				$('#zip').change();
				$('#email').change();
				$('#contact_number').change();
				$('#acct_username').change();
				$('#acct_password').change();
				$('#acct_confirm').change();
				$('#tos').change();
			  }
			// ]]>
			</script>
            <div id="body">
              <p><?php echo $this->lang->line('main_guest_intro'); ?></p>
              <div id="response">&nbsp;</div>
              <div class="form-note"><?php echo $this->lang->line('asterisk_required'); ?></div>
              <div style="position: relative;">
              <form id="theform" method="post" action="<?php echo site_url('signup/ajax'); ?>">
                <div class="form">
                  <div>
                    <span class="label"><?php echo $this->lang->line('signup_company_name'); ?><b style="color: red;">*</b></span>
                    <input class="standard" style="font-weight: bold;" type="text" size="50" id="company_name" name="company_name" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('signup_industry_type'); ?><b style="color: red;">*</b></span>
                    <select class="standard" name="industry_type" id="industry_type">
                    <option value="">Select an industry type</option>
                    <?php foreach($industry_types->result_array() as $row): ?>
                    <?php echo '<option value="' . $row['id'] . '">' . $row['title'] . '</option>'; ?>
                    <?php endforeach; ?>
                    </select>
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('signup_contact_person'); ?><b style="color: red;">*</b></span>
                    <div style="padding: 5px 10px; border: 1px solid #999999; display: inline-block;">
                      <div>
                        <span class="label"><?php echo $this->lang->line('first_name'); ?><b style="color: red;">*</b></span>
                        <input class="standard" type="text" size="25" id="first_name" name="first_name" maxlength="32" />
                      </div>
                      <div>
                        <span class="label"><?php echo $this->lang->line('last_name'); ?><b style="color: red;">*</b></span>
                        <input class="standard" type="text" size="25" id="last_name" name="last_name" maxlength="32" />
                      </div>
                    </div>
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('street_address'); ?><b style="color: red;">*</b></span>
                    <input class="standard" type="text" size="50" id="street_address" name="street_address" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('city'); ?><b style="color: red;">*</b></span>
                    <input class="standard" type="text" size="50" name="city" id="city" value="<?php echo isset($geodata['City']) ? $geodata['City'] : ''; ?>" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('state'); ?><b style="color: red;">*</b></span>
                    <input class="standard" type="text" size="50" name="state" id="state" value="<?php echo isset($geodata['RegionName']) ? $geodata['RegionName'] : ''; ?>" maxlength="128" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('country'); ?><b style="color: red;">*</b></span>
                    <select class="standard" name="country_id" id="country_id">
                    <option value="">Select a country</option>
                    <?php $geodata['CountryCode'] = isset($geodata['CountryCode']) ? $geodata['CountryCode'] : 'PH'; ?>
                    <?php foreach($countries->result_array() as $row): ?>
                    <?php $selected = ($row['abbreviation'] == $geodata['CountryCode'] ? ' selected="selected"' : ''); ?>
                    <?php echo '<option value="' . $row['id'] . '"' . $selected . '>' . $row['name'] . " ($row[abbreviation])" . '</option>'; ?>
                    <?php endforeach; ?>
                    </select>
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('zipcode'); ?></span>
                    <input class="standard" type="text" size="15" id="zip" name="zip" value="<?php echo isset($geodata['ZipPostalCode']) ? $geodata['ZipPostalCode'] : ''; ?>" maxlength="10" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('email'); ?><b style="color: red;">*</b></span>
                    <input class="standard" type="text" size="25" id="email" name="email" maxlength="64" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('contact_number'); ?><b style="color: red;">*</b></span>
                    <input class="standard" type="text" size="25" id="contact_number" name="contact_number" maxlength="32" />
                  </div>
                  <div>
                    <span class="label"><?php echo $this->lang->line('signup_account_details'); ?><b style="color: red;">*</b></span>
                    <div style="padding: 5px 10px; border: 1px solid #999999; display: inline-block;">
                      <div>
                        <span class="label"><?php echo $this->lang->line('username'); ?><b style="color: red;">*</b></span>
                        <input class="standard" type="text" size="25" id="acct_username" name="acct_username" maxlength="32" />
                      </div>
                      <div>
                        <span class="label"><?php echo $this->lang->line('password'); ?><b style="color: red;">*</b></span>
                        <input class="standard" type="password" size="25" id="acct_password" name="acct_password" maxlength="32" />
                      </div>
                      <div>
                        <span class="label"><?php echo $this->lang->line('confirm_password'); ?><b style="color: red;">*</b></span>
                        <input class="standard" type="password" size="25" id="acct_confirm" name="acct_confirm" maxlength="32" />
                      </div>
                    </div>
                  </div>
                  <div style="margin-top: 10px;">
                    <span class="label"><?php echo $this->lang->line('enter_captcha'); ?><b style="color: red;">*</b></span>
                    <div id="recaptcha"><?php echo $captcha; ?></div>
                  </div>
                  <div style="margin-top: 10px;">
                    <span class="label" id="tos-box" style="display: inline-block"><input type="checkbox" name="tos" id="tos" style="margin-right: 5px;" /><?php echo $this->lang->line('i_agree'); ?><b style="color: red;">*</b></span>
                  </div>
                  <div id="tos-div" style="display: none;"></div>
                  <a class="button-form submit" href="javascript:void(null);" id="btn-submit" style="font-size: 0.8em; margin: 20px auto;"><img src="<?php echo site_url('images/check.png'); ?>" alt="" /><?php echo $this->lang->line('signup_submit'); ?></a>
                  <noscript><div><input type="submit" value="<?php echo $this->lang->line('login_submit'); ?>" /></div></noscript>
                </div>
              </form>
              </div>
            </div>
